package com.duguo.dynamicmvc.model.validator;

import java.util.regex.Pattern;

import com.duguo.dynamicmvc.model.validator.exception.ValidationException;

public class PatternBasedValidator  extends AbstractValidator{
	
	private Pattern pattern;
	
	public PatternBasedValidator() {}
	
	public PatternBasedValidator(String pattern, String name) {
		setPattern(pattern);
		setName(name);
	}

	public void validate(String value) throws ValidationException{
		if(!pattern.matcher(value).find())
			super.validate(value);
	}

	public String getPattern() {
		return pattern.pattern();
	}

	public void setPattern(String pattern) {
		this.pattern = Pattern.compile(pattern);
	}
	
}
